<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% css_bundle :alerts %>
<% js_bundle :alerts %>

<p>
<%=
  if @context.is_a? Course
    t(:alerts_description_course,
      'An alert is generated for each student that meets all of the criteria. They are ' +
      'checked every day, and notifications will be sent to the student and/or the ' +
      'teacher until the triggering problem is resolved.')
  else
    t(:alerts_description_account,
      'An alert is generated for each student that meets all of the criteria. They are ' +
      'checked every day, and notifications will be sent to the student, teacher, and/or ' +
      'account admin until the triggering problem is resolved.')
  end
%>
</p>

<div class="alerts_list">
  {{> views/alerts/alert}}
  {{> views/alerts/alert}}
  <a href="#" class="delete_item_link editing" style="display:none;" title="{{#t}}Remove this item{{/t}}"><i class="icon-end"></i></a>
</div>

<div class="button-container" style="margin-top: 20px;">
  <button class="Button Button--primary add_alert_link">
    <span aria-hidden="true"><i class="icon-plus"></i> {{#t}}Alert{{/t}}</span>
    
  </button>
</div>

<%
  count = "%{count}" # we'll replace this with an input in js-land
  alert_data = {
    :DATA => @alerts,
    :POSSIBLE_RECIPIENTS_ORDER => [':student', ':teachers'],
    :POSSIBLE_RECIPIENTS => {
      ':student' => {:label => t(:the_student, "The Student")},
      ':teachers' => {:label => t(:the_teacher, "The Teacher")}
    },
    :POSSIBLE_CRITERIA_ORDER => ['Interaction', 'UngradedCount', 'UngradedTimespan'],
    :POSSIBLE_CRITERIA => {
      :Interaction => {
        :label => t(:description, "A teacher has not interacted with the student for %{count} days", :count => count),
        :option => t(:option, "No Teacher Interaction"),
        :title => t(:title, "Days since a teacher has interacted with the student"),
        :default_threshold => 7
      },
      :UngradedCount => {
        :label => t(:ungraded_count_description, "More than %{count} submissions have not been graded", :count => count),
        :option => t(:ungraded_count_option, "Ungraded Submissions (Count)"),
        :title => t(:ungraded_count_title, "Number of submissions that have not been graded"),
        :default_threshold => 3
      },
      :UngradedTimespan => {
        :label => t(:ungraded_timespan_description, "A submission has been left ungraded for %{count} days", :count => count),
        :option => t(:ungraded_timespan_option, "Ungraded Submissions (Time)"),
        :title => t(:ungraded_timespan_title, "Days that a submission has been left ungraded"),
        :default_threshold => 7
      }
    }
  }
  (@account_roles || []).each do |role|
    alert_data[:POSSIBLE_RECIPIENTS_ORDER] << role[:id]
    alert_data[:POSSIBLE_RECIPIENTS][role[:id]] = {:label => role[:label]}
  end
  if @context.enable_user_notes
    alert_data[:POSSIBLE_CRITERIA_ORDER] << 'UserNote'
    alert_data[:POSSIBLE_CRITERIA]['UserNote'] = {
      :label => t(:usernote_description, "No faculty journal entry has been added for %{count} days", :count => count),
      :option => t(:usernote_option, "No Faculty Journal Entry"),
      :title => t(:usernote_title, "Days since a faculty journal has been added"),
      :default_threshold => 7
    }
  end
  js_env :ALERTS => alert_data
%>
